package recognyze.transfomation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import recognyze.Mask;
import recognyze.anthropometry.Anthropometry;
import recognyze.anthropometry.BasicHormion;
import recognyze.anthropometry.Vector;

public class Transformation {

    private final Map<BasicHormion, Vector> myMap;

    protected Transformation(Map<BasicHormion, Vector> map) {
        myMap = map;
    }

    public List<Mask> transform(List<Mask> list) throws TransformationException {
        List<Mask> result = new ArrayList<Mask>();
        for(Mask m : list) {
            Anthropometry an = new Anthropometry();
            Anthropometry mAn = m.getAnthropometry();
            Set<BasicHormion> hormions =  myMap.keySet();
            for(BasicHormion bh : hormions) {
                Vector v = mAn.getPoint(bh);
                if(v == null) {
                    throw new TransformationException("Ошибка при трансформации маски " 
                    	+ m.getEmotion());
                }
                an.addPoint(bh, v.add(myMap.get(bh)));
            }
            result.add(new Mask(an, m.getEmotion()));
        }
        return result;
    }
}
